package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;

import org.testng.annotations.Test;

public class ContactModificationTests extends TestBase
{
	@Test
	public void modifySomeContact()
	{
		app.navigationTo().mainPage();
		
		//save old state
		List<ContactData> oldList = app.getContactHelper().getContacts();
		
		//actions
		app.getContactHelper().editContactByIndex(1);
		ContactData contact = new ContactData();
		contact.firstName = "New FirstName";
		contact.lastName = "New LastName";
		app.getContactHelper().fillContactForm(contact);
		app.getContactHelper().submitGroupModification();
		app.navigationTo().returnToPage("home page");
		

		//save new state
		List<ContactData> newList = app.getContactHelper().getContacts();
				
		//compare states
		oldList.remove(0);
		String name = contact.firstName + " " + contact.lastName;
		contact.firstName = name;
		oldList.add(contact);
				
		Collections.sort(oldList);		
		Collections.sort(newList);
		assertEquals(newList, oldList);
	}
}

